package cn.stacey.day12;

import java.io.File;
import java.nio.file.Files;

import org.junit.Test;

public class DemoRegex {
	@Test
	public void test() {
		String path="D:\\yuanshi\\camp2018\\camp teacher\\camp2018";
//		System.out.println(new File(path).exists());
//		File dir=new File(path);
		ListDir(new File(path));
		
		

		
	}
	public void ListDir(File dir1) {
		File[] listfiles=dir1.listFiles();
		for(File file:listfiles) {
			if(file.isDirectory()) {
				ListDir(file);
			}else {
				if(isExcel1(file.getName())) {
					System.out.println(file.getName());
				}
			}
		}
	}

	public boolean isExcel(String FileName) {
		int c=FileName.indexOf(".");
		String suffix = FileName.substring(c+1);
		if(suffix.equals("java")) {
			return true;
		}else {
			return false;
		}
		
	}
	
	//正则表达式匹配文件后缀名
	//  .*\.(docx|xlsx)
	public boolean isExcel1(String FileName) {
		return FileName.matches(".*\\.(docx|xlsx)");
	}
	
	@Test
	public void testSplit() {
		String str = "There are many resources online that can help you with the\r\n" + 
				"preparation. For the most part I read articles on system design\r\n" + 
				"interviews, architectures of large-scale systems, and case studies.";
		String[] words=str.split("[ .,\r\n]");
		for(String word:words) {
			System.out.println(word);
		}
	}
	@Test
	public void testReplace() {
		String str="1098aaassd876";
		String str1=str.replaceAll("[0-9]", "我");
		System.out.println(str1);
	}
	
	@Test
	public void test1() {
		//abc结束，前面可以放任意字符
		String regex=".*abc$";
		System.out.println("abc".matches(regex));
		System.out.println("123abc".matches(regex));
		System.out.println("abc12".matches(regex));
		
	}
	@Test
	public void test2() {
		//abc
		String regex="^abc";
		System.out.println("abcd".matches(regex));
		System.out.println("qwabcd".matches(regex));
		System.out.println("abc".matches(regex));
	}
	
	@Test
	public void test3() {
		//0个或以上的b
		String regex="ab*c";
		System.out.println("ac".matches(regex));
		System.out.println("abbc".matches(regex));
		System.out.println("bc".matches(regex));
		//0个或以上的abc
//		String regex1="(abc)*d";
//		System.out.println("abd".matches(regex1));
//		System.out.println("abcd".matches(regex1));
//		System.out.println("abcabcd".matches(regex1));
		//2-4个d
//		String regex="abc{2,4}d";
//		System.out.println("abcabcd".matches(regex));
//		System.out.println("abccd".matches(regex));
//		System.out.println("abd".matches(regex));
	}
	@Test
	public void test4() {
		//.+\.(docx|doc|xlsx|java)
//		String regex=".+\\.(docx|doc|xlsx|java)";
//		System.out.println("a.jpg".matches(regex));
//		System.out.println("s.java".matches(regex));
//		System.out.println("po.xlsx".matches(regex));
		
//		String regex1="[abcd]";
//		System.out.println("b".matches(regex1));
//		System.out.println("a".matches(regex1));
//		System.out.println("c".matches(regex1));
		
//		String regex2="(a|bcd|d)";
//		System.out.println("a".matches(regex2));
//		System.out.println("bcd".matches(regex2));
//		System.out.println("d".matches(regex2));
		
		String regex3="[a-zA-Z0-9]";
		System.out.println("b".matches(regex3));
		System.out.println("S".matches(regex3));
		System.out.println("0".matches(regex3));
		System.out.println("qqwwDDD009".matches(regex3));
		
	}
	
	@Test
	public void test5() {
		//密码是6到18位  \w表示大小写字母或者是数字      \d表示0-9的数字
		//   \w{6,18}
//		String regex="\\w{6,18}";
//		System.out.println("1234edssaa".matches(regex));
		
		//密码是6到18位，必须含有数字
		//   (?=.*\d)\w{6,18}  
//		String regex1="(?=.*\\d)\\w{6,18}";
//		System.out.println("qweARstvgy".matches(regex1));
//		System.out.println("qweARstvgy123".matches(regex1));
		
		//密码6-18位，必须含有数字，必须是大写字母开头
		// (?=.*\d)^[A-Z]\w{6,18}
		String regex2="(?=.*\\d)^[A-Z]\\w{6,18}";
		System.out.println("a14256ffgh".matches(regex2));
		System.out.println("Aa14256ffgh".matches(regex2));
		
	}
	
	
	@Test
	public void test6() {
		//非负整数
		// [1-9][0-9]*|0
//		String regex="[1-9][0-9]*|0";
//		System.out.println("090".matches(regex));
//		System.out.println("90".matches(regex));
//		System.out.println("".matches(regex));
//		System.out.println("00".matches(regex));
		
		//整数
		//   [\+\-]?[1-9]\d|0
//		String regex="[\\+\\-]?[1-9]\\d*|0";
//		System.out.println("+123".matches(regex));
//		System.out.println("-123".matches(regex));
//		System.out.println("0".matches(regex));
	}
	@Test
	public void test7() {
		//20到99的整数
		//   [2-9][0-9]*
//		String regex="[2-9][0-9]*";
//		System.out.println("78".matches(regex));
		//20到100的整数
				//   [2-9][0-9]*|100
//		String regex1="[2-9][0-9]*|100";
//		System.out.println("78".matches(regex1));
		
	}
	
	@Test
	public void test8() {
		//手机号码
		// ((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}
//		String regex="((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}";
//		System.out.println("13797025842".matches(regex));
//		System.out.println("14678789899".matches(regex));
	}
	
	@Test
	public void test9() {
		//http://www.baidu.com  网址检测
		// /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/;
		String regex="^((ht|f)tps?):\\/\\/[\\w\\-]+(\\.[\\w\\-]+)+([\\w\\-\\.,@?^=%&:\\/~\\+#]*[\\w\\-\\@?^=%&\\/~\\+#])?$";
		System.out.println("http://baidu.com".matches(regex));
	}
}
